<template lang='pug'>
.page
  .changes-manage
    .search-form.mb-10.pl-10.pr-10
      Row(type="flex" justify="start")
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 日期：
          DatePicker(:value="timeLimits" type="daterange" placement="bottom-start" placeholder="请选择日期范围" separator="至" @on-change="dateChange")
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 姓名：
          Input(v-model="name" placeholder="请输入" clearable)
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w90 身份证号码：
          Input(v-model="identityCardNO" placeholder="请输入" clearable)
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 性别：
          Select(v-model="sex_value" placeholder="请选择" clearable)
            Option(v-for="(item, index) of sex" :key="index" :value="item.value") {{item.text}}
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 异动类型：
          Select(v-model="change_type_value" placeholder="请选择" clearable)
            Option(v-for="(item, index) of change_type" :key="index" :value="item.key") {{item.value}}
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 公司名称：
          Input(v-model="companyName" placeholder="请输入" clearable)
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 社保编号：
          Select(v-model="securityNO" placeholder="请选择" clearable filterable)
            Option(v-for="(item, index) of securityNoArr" :key="index" :value="item.securityNO") {{item.securityNO}}
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 所属客服：
          Select(v-model="serverId" placeholder="请选择" filterable clearable)
            Option(v-for="(item, index) in serverId_arr" :value="item.key" :key="index") {{ item.value }}
        Col.pr-20.mb-15(:md="{ span: 24 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 处理结果：
          Select(v-model="radioValue" placeholder="请选择" clearable @on-change="radioChange" multiple :max-tag-count="2")
            template(v-for="item in change_declarestatus")
              Option(v-if="item.key!='UnDeclare'" :value="item.key") {{item.value}}
            //- template(v-for="item in change_cancelstatus")
            //-   Option(v-if="item.key!='UnCancel'" :value="item.key") {{item.value}}
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 申报时间：
          DatePicker(:value="declareTimes" type="daterange" placement="bottom" placeholder="请选择日期范围" separator="至" @on-change="declareTimesChange")
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 备注：
          Input(v-model="description" placeholder="请输入" clearable)
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }" :xxl="{span: 6}")
          span.label-txt.w80 社保专员：
          Select(v-model="commissionerUserId" label-in-value clearable filterable)
            Option(v-for="item in commissionerUserIdArr" :value="item.key" :key="item.key") {{item.value}}
          Button.ml-15(v-if="hasFind" type="info" @click="checkBtnFn") 查询

    .pl-20.pr-20.bg-white
      Table.hasTitle-table.beautiful-table(:columns="thead" :data="changeList" :stripe="true" :loading="loading" @on-selection-change="tableSelectChange")
        .clearfix.font-14(slot="header")
          .table-title-lefttxt.pull-left
            span
              |合计:
              span.text-info.pl-5.pr-5.font-weight {{codeTotal}}
              | 人
            Divider(type="vertical")
            span
              | 新增:
              span.text-info.pl-5.pr-5.font-weight {{typeStatList && typeStatList[1]}}
              | 人
            Divider(type="vertical")
            span
              | 减少:
              span.text-info.pl-5.pr-5.font-weight {{typeStatList && typeStatList[2]}}
              | 人
          .pull-right.table-title-btns
            Button.mr-10(v-if="hasAuditUnDeclare" size="small" type="info" @click="AuditUnDeclareFunc") 审核未申报
            Button.mr-10(v-if="hasDeclareSuccess" size="small" type="info" @click="passFn") 申报成功
            Button.mr-10(v-if="hasDeclareFail" size="small" type="info" @click="noPassFn") 申报失败
            Button.mr-10(v-if="hasCancelDeclare" size="small" type="info" @click="cancelDeclare") 取消申报
            Dropdown(placement="bottom-end" @on-click="handleFunc")
              span.ml-10 更多
                Icon(type="ios-arrow-down")
              DropdownMenu(slot="list")
                DropdownItem(v-if="hasExportAndLock" name="1") 导出并锁定
                DropdownItem(v-if="hasExport" name="2" divided) 导出
                DropdownItem(v-if="hasDownloadPictureFile" name="3" divided) 照片下载
        template(slot-scope="{ row, index }" slot="action")
          Button.mr-10(v-if="hasGetProcessList" size="small" @click="handleShowProcessModal(row)") 查看异动审核流程
        .clearfix.pl-20.pr-20(slot="footer")
          Page(:total="codeTotal" :current="PageIndex" :page-size="PageSize" prev-text="上一页" next-text="下一页" @on-change="pageChangeFn" show-total @on-page-size-change="onpageSizeChange" show-sizer :page-size-opts="[10, 20, 30, 50, 100]")
    Modal(v-model="templateModal" title="选择导出模板")
      RadioGroup(v-model="templateId" vertical style="width:100%")
        .d-f-c.mb-10(v-for="(item,index) in templateList" :key="index")
          Radio(:label="item.id")
            span {{item.name}}
          .action
            Button.mr-10(type="info" size="small" @click="updateTemlate(item.id, item.name)") 编辑
            Button(type="warning" size="small" @click="deleteTemlate(item.id)") 删除
      div(slot="footer")
        Button(@click="chooseTemplateCancel") 取消
        Button(type="info" @click="addTemplate") 添加模板
        Button(type="info" @click="chooseTemplate") 确定

    Modal(v-model="customizeTemplateModal" title="自定义模板" width="520px")
      .template-title.mb-15
        span 模板名称：
        Input(v-model="customizeTemplateTitle" type="text" style="width:auto" placeholder="请输入")
      .ivu-transfer
        .ivu-transfer-list.mr-15(style="height:350px")
          .ivu-transfer-list-header
            Checkbox(v-model="isAllSelect" @on-change="selectAll")
              | 待选字段
          .ivu-transfer-list-body
            .ivu-transfer-list-content
              CheckboxGroup(v-model="transferDataValue"
              @on-change="transferDataChange")
                template(v-for="(item,index) in transferData_filter")
                  .ivu-transfer-list-content-item
                    Checkbox(:label="item.key")
                      span {{item.value}}
        .ivu-transfer-list(style="width:250px;height:350px")
          .ivu-transfer-list-header
            | 已选字段
          .ivu-transfer-list-body
            .ivu-transfer-list-content
              .ivu-transfer-list-content-item(v-for="(item,index) in transferKeys")
                span {{item.value}}
                span.pull-right
                  Button(size="small" @click="upGo(transferKeys,index)")
                    Icon(type="md-arrow-up")
                  Button(size="small" @click="downGo(transferKeys,index)")
                    Icon(type="md-arrow-down")
      div(slot="footer")
        Button(@click="customizeCancel") 取消
        Button(type="info" @click="customizeConfirm") 确定
    //- 异动审核流程弹窗
    ProcessModal(ref="ProcessModal")
</template>

<script>
import dataApi from '@/api/data.js'
import changeManageApi from '@/api/changeManage.js'
import Mixin from './ssMixin.js'
import ProcessModal from '../../business-sector/changesManage/modals/processModal.vue'

export default {
  name: 'ssChangesManage',
  components: { ProcessModal },
  data () {
    return {
      commissionerUserId: '',
      commissionerUserIdArr: [],

      FilterType: '',
      timeLimits: [], // 时间范围
      declareTimes: [], // 申报时间范围
      declareBeginTime: '',
      declareEndTime: '',
      radioValue: [], // 处理结果显示
      typeStatList: null,

      isLock: false,
      templateModal: false, // 导出模板
      templateType: 11, // 导出模板类型：11-社保，12-公积金，13-商保
      templateList: null, // 导出模板列表
      templateId: '', // 模板id
      customizeTemplateModal: false, // 自定义模态窗
      customizeTemplateTitle: '', // 自定义模版名称
      isAllSelect: false, // 自定义模板中的全选字段
      transferData: [],
      transferData_filter: [],
      transferDataValue: [],
      transferKeys: [],
      transferKeysValue: [],

      templateModal: false, // 导出模板
      // 异动参保类型(1社会保险、2公积金、3商保)
      securityType: 1,
      // 导出类型(1审核，2查询，3管理)
      ExportType: 3,
      // 所处阶段
      period: 2,
      // 异动开始时间
      changeBeginTime: '',
      // 结束时间
      changeEndTime: '',
      // 姓名
      name: '',
      // 身份证号码
      identityCardNO: '',
      // 性别
      sex: [{ name: 'Female', value: 2, text: '女' }, { name: 'Man', value: 1, text: '男' }],
      sex_value: null,
      // 异动类型
      change_type: [],
      change_type_value: '',
      // 公司名称
      companyName: '',
      securityNoArr: [], // 编号数组
      // 社保编号
      securityNO: '',
      // 申报处理结果
      change_declarestatus: [],
      change_declarestatus_value: [],
      // 撤销处理结果
      change_cancelstatus: [],
      change_cancelstatus_value: [],
      serverId_arr: [], // 所属客服下拉
      // 所属客服
      serverId: '',
      description: '', // 备注
      // 选择的id合集
      selectedId: '',
      employeeGUID: [], // 员工id
      // 申报的相关状态码（0未申报、1待申报、2申报失败、3申报成功）
      _Status: null,
      // 审核意见
      _Reason: '',
      // 通过弹窗
      modal_1: false,
      // 同意撤销弹窗
      modal_2: false,
      // 不同意撤销弹窗
      modal_3: false,
      thead: [],
      changeList: [],
      codeTotal: 0,
      PageIndex: 1,
      PageSize: 10,
      loading: false,
      // 下载路径
      downLoadRul: ''

    }
  },
  mixins: [Mixin],
  created () {
    this.getEnum()
    this.initPage()
    this.serverDown()
    this.getSecurityNoArr()
  },
  computed: {
    actionArr () {
      let arr = this.$store.state.user.actionAccess.map(item => {
        return item.code
      })
      return arr
    },
    // 导出
    hasExport () {
      return this.actionArr.indexOf('Export') > -1
    },
    // 查询
    hasFind () {
      return this.actionArr.indexOf('Find') > -1
    },
    // 照片下载
    hasDownloadPictureFile () {
      return this.actionArr.indexOf('DownloadPictureFile') > -1
    },
    // 取消申报
    hasCancelDeclare () {
      return this.actionArr.indexOf('CancelDeclare') > -1
    },
    // 申报失败
    hasDeclareFail () {
      return this.actionArr.indexOf('DeclareFail') > -1
    },
    // 申报成功
    hasDeclareSuccess () {
      return this.actionArr.indexOf('DeclareSuccess') > -1
    },
    // 导出并锁定
    hasExportAndLock () {
      return this.actionArr.indexOf('ExportAndLock') > -1
    },
    // 审核未申报
    hasAuditUnDeclare () {
      return this.actionArr.indexOf('AuditUnDeclare') > -1
    },
    // 查看异动审核流程权限编码
    hasGetProcessList () {
      return this.actionArr.indexOf('GetProcessList') > -1
    }
  },
  watch: {
    $route (to, from) {
      if (from.name === 'home') {
        this.initPage()
      }
    }
  },

  methods: {
    handleFunc (val) {
      switch (val) {
        case "1":
          this.exportBtn(true)
          break
        case "2":
          this.exportBtn(false)
          break
        case "3":
          this.downLoad()
          break
      }
    },
    // 审核未申报
    AuditUnDeclareFunc () {
      if (this.selectedId) {
        this._Status = 4
        this._Reason = ''
        this.$Modal.confirm({
          title: '确定执行该操作（审核未申报）？',
          onOk: () => {
            this.changeDeclare()
          },
          onCancel: () => {

          }
        })
      } else {
        this.$Message.warning('请选择你需要操作的条目')
      }
    },
    // 获取当月一号到当前时间
    getTime () {
      let myDate = new Date()
      let thisyear = myDate.getFullYear()
      let thismonth = myDate.getMonth() + 1
      let thisday = myDate.getDate()
      let beginTime = thisyear + '-' + this.toDouble(thismonth) + '-01'
      let endTime = thisyear + '-' + this.toDouble(thismonth) + '-' + this.toDouble(thisday)
      return [beginTime, endTime]
    },
    // 补零
    toDouble (now) {
      return now > 9 ? '' + now : '0' + now
    },
    // 获取编号数据
    getSecurityNoArr () {
      changeManageApi.GetSecurityNoList({
        SecurityType: this.securityType,
        HasPaging: false
      }).then(res => {
        console.log(res)
        if (res.data.success) {
          this.securityNoArr = res.data.data
        } else {
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 初始化
    initPage () {

      if (this.$route.params.hasTime && !this.$route.params.hasStatus) {
        this.timeLimits = this.getTime()
        this.changeBeginTime = this.timeLimits[0]
        this.changeEndTime = this.timeLimits[1]
        this.radioValue = []
        this.change_declarestatus_value = []
      }
      if (this.$route.params.hasStatus && !this.$route.params.hasTime) {
        switch (this.$route.params.status) {
          case 4:
            this.radioValue = ['DeclareApplying', 'AuditUnDeclare']
            this.change_declarestatus_value = ['DeclareApplying', 'AuditUnDeclare']
            break;
          case 2:
            this.radioValue = ['DeclareFail']
            this.change_declarestatus_value = ['DeclareFail']
            break;
        }
        this.timeLimits = []
        this.changeBeginTime = ''
        this.changeEndTime = ''
      }
      if (!this.$route.params.hasStatus && !this.$route.params.hasTime) {
        this.radioValue = ['DeclareApplying', 'AuditUnDeclare']
        this.change_declarestatus_value = ['DeclareApplying', 'AuditUnDeclare']
        this.timeLimits = []
        this.changeBeginTime = ''
        this.changeEndTime = ''
      }
      this.getList()
    },
    /**
     * 分页页码变动
     */
    onpageSizeChange (val) {
      this.PageIndex = 1
      this.PageSize = val
      this.getList()
    },
    // 获取列表
    getList () {
      let thead_extend = ['selection', 'companyName', 'changeType', 'identityCardNO', 'name', 'sex', 'birthDay', 'statusName', 'declareReason', 'securityNO', 'planName', 'commissionerUserName', 'serverName', 'employeeTypeName', 'changeTime', 'declareSalary', 'action']
      this.loading = true
      changeManageApi.getChangeList({
        FilterType: this.FilterType,
        ExportType: this.ExportType,
        SecurityType: this.securityType,
        Period: this.period,
        ChangeBeginTime: this.changeBeginTime,
        ChangeBeginTime: this.changeBeginTime,
        ChangeEndTime: this.changeEndTime,
        Name: this.name,
        IdentityCardNO: this.identityCardNO,
        Sex: this.sex_value,
        ChangeType: this.change_type_value,
        CompanyName: this.companyName,
        SecurityNO: this.securityNO,
        // DeclareStatus: this.change_declarestatus_value,
        // CancelStatus: this.change_cancelstatus_value,
        ListStatus: this.radioValue,
        DeclareBeginTime: this.declareBeginTime,
        DeclareEndTime: this.declareEndTime,
        ServerId: this.serverId,
        Description: this.description,
        CommissionerUserId: this.commissionerUserId,
        PageIndex: this.PageIndex,
        PageSize: this.PageSize
      }).then(res => {
        this.security = res.data.data.security
        if (res.data.data.securityMerge) {
          thead_extend.push('baseAmount')
          this.security.forEach(item => {
            switch (item.code) {
              case 'SeriousIllness': // 大病医疗
                if (item.showCompany) {
                  thead_extend.push('seriousIllness_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('seriousIllness_e')
                }
                break
              case 'DisabledPersonsSecurityFund': // 残疾人保障金
                if (item.showCompany) {
                  thead_extend.push('disabledPersonsSecurityFund')
                }
                break
              case 'OutpatientDepartment': // 门诊医疗
                if (item.showCompany) {
                  thead_extend.push('outpatientDepartment_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('outpatientDepartment_e')
                }
                break
            }
          })
          thead_extend.push('leaveReason', 'description', 'phone', 'idCardEndTime', 'duty', 'residentAddress', 'auditTime')
          this.thead = this.getTableColumns(thead_extend)
        } else {
          this.security.forEach(item => {
            switch (item.code) {
              case 'Pension': // 养老
                if (item.showCompany) {
                  thead_extend.push('pension_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('pension_e')
                }
                break
              case 'MedicalCare': // 医疗
                if (item.showCompany) {
                  thead_extend.push('medicalCare_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('medicalCare_e')
                }
                break
              case 'Unemployment': // 失业
                if (item.showCompany) {
                  thead_extend.push('unemployment_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('unemployment_e')
                }
                break
              case 'InjuryOnTheJob': // 工伤
                if (item.showCompany) {
                  thead_extend.push('injuryOnTheJob_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('injuryOnTheJob_e')
                }
                break
              case 'Birth': // 生育
                if (item.showCompany) {
                  thead_extend.push('birth_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('birth_e')
                }
                break
              case 'SeriousIllness': // 大病医疗
                if (item.showCompany) {
                  thead_extend.push('seriousIllness_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('seriousIllness_e')
                }
                break
              case 'DisabledPersonsSecurityFund': // 残疾人保障金
                if (item.showCompany) {
                  thead_extend.push('disabledPersonsSecurityFund')
                }
                break
              case 'OutpatientDepartment': // 门诊医疗
                if (item.showCompany) {
                  thead_extend.push('outpatientDepartment_c')
                }
                if (item.showPersonal) {
                  thead_extend.push('outpatientDepartment_e')
                }
                break
            }
          })
          thead_extend.push('leaveReason', 'description', 'phone', 'idCardEndTime', 'duty', 'residentAddress', 'auditTime')
          this.thead = this.getTableColumns(thead_extend)
        }
        this.selectedId = ''
        // console.log(this.security)
        this.changeList = res.data.data.list
        this.typeStatList = res.data.data.typeStatList
        this.codeTotal = res.data.totalRows
        this.loading = false
      })
    },
    // 获取下拉
    async getEnum () {
      let groupNames = 'change.socialsecuritytype,change.auditstatus,change.managestatus,change.cancelstatus2,user.supplierlist'
      let res = await dataApi.getEnum({
        groupName: groupNames
      })
      // console.log(res.data)
      this.change_type = this.getItems(res.data, 'change.socialsecuritytype')
      this.change_declarestatus = this.getItems(res.data, 'change.managestatus')
      this.change_cancelstatus = this.getItems(res.data, 'change.cancelstatus2')
      this.commissionerUserIdArr = this.getItems(res.data, 'user.supplierlist')
    },
    getItems (arr, key) {
      let object = arr.find((item) => {
        return item.group === key
      })
      return object.items
    },
    // 操作申报相关
    async changeDeclare () {
      let res = await changeManageApi.changeDeclare({
        Ids: this.selectedId,
        Status: this._Status,
        Reason: this._Reason
      })
      // console.log(res.data)
      if (res.data.success) {
        this.$Message.success('操作成功！')
        this.getList()
      } else {
        this.$Message.error({
          content: res.data.message,
          duration: 10,
          closable: true
        })
      }
    },

    // 获取导出模板列表
    getExportList () {
      changeManageApi.GetExportList({
        type: this.templateType
      }).then(res => {
        console.log(res)
        this.templateList = res.data.data
      })
    },
    // 导出
    exportBtn (Boolean) {
      // if(this.selectedId) {
      this.isLock = Boolean
      console.log(this.isLock)
      this.templateModal = true
      this.getExportList()
    },
    // 自定义模板

    transferDataChange (val) {
      if (val) {
        console.log(this.transferData_filter.length)
        if (val.length === this.transferData_filter.length) {
          this.isAllSelect = true
        } else {
          this.isAllSelect = false
        }
      }
      this.transferKeys = this.transferData_filter.filter(item => this.transferDataValue.some(ele => ele === item.key))
    },
    selectAll () {
      if (this.isAllSelect) {
        this.transferDataValue = this.transferData_filter.map(item => {
          return item.key
        })
      } else {
        this.transferDataValue = []
      }
      this.transferDataChange()
    },
    upGo (transferKeys, index) {
      if (index != 0) {
        transferKeys[index] = transferKeys.splice(index - 1, 1, transferKeys[index])[0]
      } else {
        // transferKeys.push(transferKeys.shift())
        return false
      }
    },
    downGo (transferKeys, index) {
      if (index != transferKeys.length - 1) {
        transferKeys[index] = transferKeys.splice(index + 1, 1, transferKeys[index])[0]
      } else {
        // transferKeys.unshift( transferKeys.splice(index,1)[0])
        return false
      }
    },

    // 添加模板按钮
    addTemplate () {
      this.templateId = ''
      this.customizeTemplateTitle = ''
      this.customizeTemplateModal = true
      this.transferKeys = []
      this.transferData_filter = []
      this.transferDataValue = []
      changeManageApi.GetCustomize({
        BusinessType: this.templateType,
        Type: 2
      }).then(res => {
        console.log(res)
        this.transferData = res.data.data.chosenColumnList
        this.getLastData(this.transferData, this.transferData_filter)
        console.log(this.transferData_filter)
      })
    },
    // 编辑自定义模板
    updateTemlate (id, name) {
      this.templateId = id
      this.customizeTemplateTitle = name
      this.customizeTemplateModal = true
      this.transferData_filter = []
      changeManageApi.GetCustomize({
        id: id,
        BusinessType: this.templateType,
        Type: 2
      }).then(res => {
        this.transferData = res.data.data.chosenColumnList
        this.getLastData(this.transferData, this.transferData_filter)
        this.transferKeys = res.data.data.selectedColumnList
        this.transferDataValue = this.transferKeys.map(item => {
          return item.key
        })
      })
    },
    // 删除自定义模板
    deleteTemlate (id) {
      changeManageApi.deleteCustomize({
        id: id
      }).then(res => {
        if (res.data.success) {
          this.$Message.success(res.data.message)
          this.getExportList()
        } else {
          
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 获取最后一级数据
    getLastData (arr, arr_2) {
      arr.forEach(item => {
        // arr_2.push(item)
        if (item.childs) {
          this.getLastData(item.childs, arr_2)
        } else {
          arr_2.push(item)
        }
      })
    },
    // 自定义模板取消
    customizeCancel () { this.customizeTemplateModal = false },
    // 自定义模板确定
    customizeConfirm () {
      if (this.transferKeys.length > 0) {
        let detail = []
        this.transferKeys.forEach(item => {
          detail.push({
            name: item.value,
            code: item.key
          })
        })
        changeManageApi.SaveCustomize({
          id: this.templateId,
          BusinessType: this.templateType,
          Type: 2,
          Name: this.customizeTemplateTitle,
          Detail: detail
        }).then(res => {
          if (res.data.success) {
            this.getExportList()
            this.$Message.success(res.data.message)
            this.customizeTemplateModal = false
          } else {
            
            this.$Message.error({
              content: res.data.message,
              duration: 10,
              closable: true
            })
          }
        })
      } else {
        this.$Message.warning('请选择字段')
      }
    },
    // 模板选择取消
    chooseTemplateCancel () {
      this.templateModal = false
    },
    // 选择模板之后确定
    chooseTemplate () {
      console.log(this.templateId)
      if (this.isLock) {
        changeManageApi.ExportAndLock({
          ExportType: this.ExportType,
          Ids: this.selectedId,
          TemplateId: this.templateId,
          SecurityType: this.securityType,
          Period: this.period,
          ChangeBeginTime: this.changeBeginTime,
          ChangeEndTime: this.changeEndTime,
          Name: this.name,
          IdentityCardNO: this.identityCardNO,
          Sex: this.sex_value,
          ChangeType: this.change_type_value,
          CompanyName: this.companyName,
          SecurityNO: this.securityNO,
          // DeclareStatus: this.change_declarestatus_value,
          // CancelStatus: this.change_cancelstatus_value,
          ListStatus: this.radioValue,
          DeclareBeginTime: this.declareBeginTime,
          DeclareEndTime: this.declareEndTime,
          ServerId: this.serverId,
          CommissionerUserId: this.commissionerUserId,
          PageIndex: this.PageIndex,
          PageSize: this.PageSize
        }).then(res => {
          console.log(res)
          let fileName = '社保异动管理.xls'
          // 获取文件名
          let blob = new Blob([res.data], { type: 'application/octet-stream' })
          if ('download' in document.createElement('a')) {
            let objectUrl = URL.createObjectURL(blob)
            const link = document.createElement('a')
            link.download = fileName
            link.href = objectUrl
            link.click()
          } else {
            navigator.msSaveBlob(blob, fileName)
          }
          this.templateModal = false
        })
      } else {
        changeManageApi.Export({
          ExportType: this.ExportType,
          Ids: this.selectedId,
          TemplateId: this.templateId,
          SecurityType: this.securityType,
          Period: this.period,
          ChangeBeginTime: this.changeBeginTime,
          ChangeEndTime: this.changeEndTime,
          Name: this.name,
          IdentityCardNO: this.identityCardNO,
          Sex: this.sex_value,
          ChangeType: this.change_type_value,
          CompanyName: this.companyName,
          SecurityNO: this.securityNO,
          // DeclareStatus: this.change_declarestatus_value,
          // CancelStatus: this.change_cancelstatus_value,
          ListStatus: this.radioValue,
          DeclareBeginTime: this.declareBeginTime,
          DeclareEndTime: this.declareEndTime,
          ServerId: this.serverId,
          CommissionerUserId: this.commissionerUserId,
          PageIndex: this.PageIndex,
          PageSize: this.PageSize
        }).then(res => {
          console.log(res)
          let fileName = '社保异动管理.xls'
          let blob = new Blob([res.data], { type: 'application/octet-stream' })
          if ('download' in document.createElement('a')) {
            let objectUrl = URL.createObjectURL(blob)
            const link = document.createElement('a')
            link.download = fileName
            link.href = objectUrl
            link.click()
          } else {
            navigator.msSaveBlob(blob, fileName)
          }
          this.templateModal = false
        })
      }
    },
    // 显示全部
    showAll () {
      this.PageSize = this.codeTotal
      this.PageIndex = 1
      this.getList()
    },
    // 下载附件
    downLoad () {
      if (this.employeeGUID.length > 0) {
        changeManageApi.downLoad(this.employeeGUID).then((res) => {
          if (res.data.success) {
            let fileName = '员工照片.zip'
            const link = document.createElement('a')
            link.download = fileName
            link.href = res.data.message
            link.click()
          } else {
            
            this.$Message.error({
              content: res.data.message,
              duration: 10,
              closable: true
            })
          }
        })
      } else {
        this.$Message.warning('您还未做任何选择！！')
      }
    },
    // 筛选日期变动时
    dateChange (val) {
      console.log(val)
      this.changeBeginTime = val[0]
      this.changeEndTime = val[1]
    },
    // 申报时间变动
    declareTimesChange (val) {
      this.declareBeginTime = val[0]
      this.declareEndTime = val[1]
    },
    // 处理结果改变时
    radioChange (val) {
      console.log('处理结果改变时 val: ', val)
      this.change_declarestatus_value = []
      this.change_cancelstatus_value = []
      const models_1 = ['UnDeclare', 'DeclareApplying', 'DeclareFail', 'DeclareSuccess', 'AuditUnDeclare'] // 申报结果
      const models_2 = ['1', '3'] // 撤销结果 0未申报、1待申报、2申报失败、3申报成功
      // if (models_1.includes(val)) {
      //   this.change_declarestatus_value = val
      //   this.change_cancelstatus_value = ''
      // } else if (models_2.includes(val)) {
      //   this.change_cancelstatus_value = val
      //   this.change_declarestatus_value = ''
      // } else {
      //   this.change_declarestatus_value = ''
      //   this.change_cancelstatus_value = ''
      // }
      if (val) {
        val.map(vi => {
          if (models_1.includes(vi)) {
            this.change_declarestatus_value.push(vi)
            this.change_cancelstatus_value = []
          } else if (models_2.includes(vi)) {
            this.change_cancelstatus_value.push(vi)
            this.change_declarestatus_value = []
          } else {
            this.change_declarestatus_value = []
            this.change_cancelstatus_value = []
          }
        })
      } else {
        this.change_declarestatus_value = []
        this.change_cancelstatus_value = []
      }
    },
    // 查询
    checkBtnFn () {
      this.FilterType = ''
      this.PageIndex = 1
      this.getList()
    },
    // table选择
    tableSelectChange (value) {
      // console.log(value)
      let arr = value.map((item) => {
        return item.id
      })
      this.selectedId = arr.join(',')
      this.employeeGUID = value.map((item) => {
        return item.employeeGUID
      })
    },
    // 通过
    passFn () {
      if (this.selectedId) {
        this._Status = 3
        this._Reason = ''
        this.$Modal.confirm({
          title: '确定通过？',
          onOk: () => {
            this.changeDeclare()
          },
          onCancel: () => {

          }
        })
      } else {
        this.$Message.warning('请选择你需要操作的条目')
      }
    },
    // 不通过
    noPassFn () {
      if (this.selectedId) {
        this._Status = 2
        this._Reason = ''
        this.$Modal.confirm({
          render: h => {
            return h('Input', {
              props: {
                value: this._Reason,
                autofocus: true,
                clearable: true,
                placeholder: '请输入不通过的原因'
              },
              on: {
                input: val => {
                  this._Reason = val
                }
              }
            })
          },
          onOk: () => {
            console.log(this._Reason)
            this.changeDeclare()
          }
        })
      } else {
        this.$Message.warning('请选择你需要操作的条目')
      }
    },
    // 取消申报
    cancelDeclare () {
      if (this.selectedId) {
        this._Status = 1
        this._Reason = ''
        this.$Modal.confirm({
          title: '确定取消申报？',
          onOk: () => {
            this.changeDeclare()
            this.getList()
          },
          onCancel: () => {
          }
        })
      } else {
        this.$Message.warning('请选择你需要操作的条目')
      }
    },
    // 分页
    pageChangeFn (index) {
      this.PageIndex = index
      this.getList()
    },
    /**
     * server所属客服下拉数据
     */
    serverDown () {
      let data = {
        pageIndex: 1,
        pageSize: 1000
      }
      dataApi.postServers(data).then(res => {
        if (res.data[0] && res.data[0].items) {
          this.serverId_arr = res.data[0].items
        }
      })
    },

    handleShowProcessModal(row) {
      this.$refs.ProcessModal.show(row)
    }
  }
}
</script>

<style lang="less" scoped>
  .d-f-c{
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
</style>
